package com.ruoyi.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.user.domain.WalletTransactionLog;
import com.ruoyi.user.service.IWalletTransactionLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 零钱流水Controller
 * 
 * @author ruoyi
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/user/log")
public class WalletTransactionLogController extends BaseController
{
    @Autowired
    private IWalletTransactionLogService walletTransactionLogService;

    /**
     * 查询零钱流水列表
     */
    @PreAuthorize("@ss.hasPermi('user:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(WalletTransactionLog walletTransactionLog)
    {
        startPage();
        List<WalletTransactionLog> list = walletTransactionLogService.selectWalletTransactionLogList(walletTransactionLog);
        return getDataTable(list);
    }

    /**
     * 导出零钱流水列表
     */
    @PreAuthorize("@ss.hasPermi('user:log:export')")
    @Log(title = "零钱流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WalletTransactionLog walletTransactionLog)
    {
        List<WalletTransactionLog> list = walletTransactionLogService.selectWalletTransactionLogList(walletTransactionLog);
        ExcelUtil<WalletTransactionLog> util = new ExcelUtil<WalletTransactionLog>(WalletTransactionLog.class);
        util.exportExcel(response, list, "零钱流水数据");
    }

    /**
     * 获取零钱流水详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:log:query')")
    @GetMapping(value = "/{txnId}")
    public AjaxResult getInfo(@PathVariable("txnId") String txnId)
    {
        return success(walletTransactionLogService.selectWalletTransactionLogByTxnId(txnId));
    }

    /**
     * 新增零钱流水
     */
    @PreAuthorize("@ss.hasPermi('user:log:add')")
    @Log(title = "零钱流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WalletTransactionLog walletTransactionLog)
    {
        return toAjax(walletTransactionLogService.insertWalletTransactionLog(walletTransactionLog));
    }

    /**
     * 修改零钱流水
     */
    @PreAuthorize("@ss.hasPermi('user:log:edit')")
    @Log(title = "零钱流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WalletTransactionLog walletTransactionLog)
    {
        return toAjax(walletTransactionLogService.updateWalletTransactionLog(walletTransactionLog));
    }

    /**
     * 删除零钱流水
     */
    @PreAuthorize("@ss.hasPermi('user:log:remove')")
    @Log(title = "零钱流水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{txnIds}")
    public AjaxResult remove(@PathVariable String[] txnIds)
    {
        return toAjax(walletTransactionLogService.deleteWalletTransactionLogByTxnIds(txnIds));
    }

    /**
     * 根据用户ID和钱包ID查询零钱流水列表
     */
    @PreAuthorize("@ss.hasPermi('user:log:list')")
    @GetMapping("/customer/{customerId}/wallet/{walletId}")
    public AjaxResult getTransactionsByCustomerAndWallet(@PathVariable String customerId, @PathVariable String walletId)
    {
        List<WalletTransactionLog> list = walletTransactionLogService.selectWalletTransactionLogByCustomerIdAndWalletId(customerId, walletId);
        return AjaxResult.success("查询成功", list);
    }
}
